var M = {};
define("M",["lib/utils/fns", "lib/utils/filter_builder", "lib/filters/script_filter"],function ($fn, $filter, filters) {
    if(!isEmptyObject(filters)){
        $filter.filters = filters;
    }

    var Motor = {};
    Motor.require = function (name) {
        if (!isBlank(name)) {
            var arr =name.match(/[A-Z]/g);
            for(var i in arr){
                name = name.replace(arr[i], "/"+arr[i].toLowerCase());
            }
            return require("moudles/"+name);
        }
    }
    function script(name, func, type) {
        if(isNull(func) && isFunction(name)){
            func = name;
        }
        if(isNull(type)){
            type = "script";
        }

        var arr = $fn.getArgs(func);
        var scripts = [];
        for(var i in arr){
            scripts.push(Motor.require(arr[i]));
        }
        var scriptObj = func.apply({
            name:name,
            scriptType:type
        },scripts);
        return scriptObj;
    }
    Motor.define = function (name, func) {
        return script(name, func, "script");
    }
    Motor.api = function (name, func) {
        return script(name, func, "api");
    }
    Motor.page = function (name, func) {
        return script(name, func, "page");
    }
    Motor.facade = function (name, func) {
        return script(name, func, "facade");
    }
    Motor.service = function (name, func) {
        return script(name, func, "service");
    }
    M = $filter.createProxy("M", Motor , "script");
    return M;
});